# --coding:utf-8--
# MakeBy: LiuBoyuan


class FormClass:
    def collection(self, filter_callback=None):
        """
        将Form类进行表单的展示并收集成json
        :param filter_callback: 一个验证函数的句柄，第一个参数默认是json的键第二个是json的值
        :return:
        """
        formNames, allFormComponents = self.__dict__.keys(), self.__dict__.values()

        ret_json = {}
        for formName, formCompent in zip(formNames, allFormComponents):
            ret_json[formName] = formCompent.formShow()
            if filter_callback is not None:  # 是否开启验证
                while True:
                    flag, key, value = filter_callback(formName, ret_json[formName])
                    if flag:
                        ret_json[key] = value
                        break  # 结果验证是否正确
                    else:
                        self.collection(filter_callback=None)

        return ret_json
